﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageK.Java
{
    public class PixelGrabber
    {
        public PixelGrabber() 
        {
            
        }


        // Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.
        //     Returns:
        // true if the pixels were successfully grabbed, false on abort, error or timeout
        // Throws:
        // InterruptedException – Another thread has interrupted this thread.
        public void grabPixels(Bitmap producer, ref int[] intPixels)
        {
            intPixels = new int[producer.Width * producer.Height];
            for (int i = 0; i < producer.Height; ++i)
            {
                for (int j = 0; j < producer.Width; ++j)
                {
                    Color col = producer.GetPixel(j, i); //从像素度颜色到变量col
                    intPixels[i*producer.Width + j]= (int)(col.R << 16) + (int)(col.G << 8) | col.B;
                }
            }
        }
    }
}
